package com.share.demo.zkclient;

import org.I0Itec.zkclient.IZkStateListener;
import org.apache.zookeeper.Watcher;

/**
*
* @date 2018/01/03
* @author caifan 
*
*/
public class ZKStateListener implements IZkStateListener {
    @Override
    public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception {
        String stateStr = null;
        switch (keeperState) {
            case Disconnected:
                stateStr = "Disconnected";
                break;
            case Expired:
                stateStr = "Expired";
                break;
            case NoSyncConnected:
                stateStr = "NoSyncConnected";
                break;
            case SyncConnected:
                stateStr = "SyncConnected";
                break;
            case Unknown:
            default:
                stateStr = "Unknow";
                break;
        }
        System.out.println("[Callback]State changed to [" + stateStr + "]");
    }

    @Override
    public void handleNewSession() throws Exception {
        System.out.println("new session create");
    }

    @Override
    public void handleSessionEstablishmentError(Throwable throwable) throws Exception {

    }
}
